package com.zx.kitchen.index.common.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.zx.kitchen.index.R;
import com.zx.kitchen.index.common.utils.treeviewutil.Node;
import com.zx.kitchen.index.common.utils.treeviewutil.adapter.TreeListViewAdapter;

import java.util.List;

/**
 * Created by Administrator on 2017/3/16.
 */

public class CateTreeListViewAdapter<T> extends TreeListViewAdapter<T> {
    private int select = 0;
    public CateTreeListViewAdapter(Context context, ListView tree, List<T> datas, int defaultExpandLevel) throws IllegalAccessException, IllegalArgumentException {
        super(context, tree, datas, defaultExpandLevel);
    }

    public void setSelect(int select) {
        this.select = select;
        notifyDataSetChanged();
    }
    @Override
    public View getConvertView(Node node, int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView==null) {
            //设置false返回的是单个listview true返回的是包含父view的viewgroup
            convertView = mInflater.inflate(R.layout.adapter_catelist, parent, false);
            holder = new ViewHolder();
        ;
            holder.catelistName = (TextView) convertView.findViewById(R.id.catelist_name);
            holder.llCatelist = (LinearLayout) convertView.findViewById(R.id.ll_catelist);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.catelistName.setText(node.getName());
        holder.isnotCheck();
        if (select == position) {
            holder.check();
        }
        return convertView;
    }
    protected class ViewHolder {
        private LinearLayout llCatelist;
        private TextView catelistName;

        public void check() {
            llCatelist.setBackgroundColor(mContext.getResources().getColor(R.color.blue));
            catelistName.setTextColor(mContext.getResources().getColor(R.color.white));
        }

        public void isnotCheck() {
            llCatelist.setBackgroundColor(mContext.getResources().getColor(R.color.white));
            catelistName.setTextColor(mContext.getResources().getColor(R.color.black));
        }
    }
}
